package com.xiyi.shouxin.init;

import javax.annotation.PostConstruct;

import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class InitProcessor {
    @Autowired
    private CacheUtil cacheUtil;
    @Autowired
    private Logger logger;

    @PostConstruct
    public void initHandle() {
        new Thread(() -> {
            while (true) {
                try {
                    DelayTask task = cacheUtil.takeDelayTask();
                    cacheUtil.removeTokenAdmin(task.getToken());
                    cacheUtil.removeTokenUser(task.getToken());
                    cacheUtil.removePhoneCode(task.getToken());
                } catch (InterruptedException e) {
                    logger.error("延时队列中断", e);
                }
            }
        }).start();
    }
}
